package ac.neec.mio.ui.activity;

import java.io.Serializable;

import ac.neec.mio.R;
import ac.neec.mio.ui.fragment.RecordListFragment;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

public class RecordActivity extends Activity implements
		 OnGestureListener, Serializable {

	private GestureDetector detector;
	private RecordListFragment fragment;
//	private Button selectButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_record);
		initFindViews();
		setRecordList();

		detector = new GestureDetector(this, this);
	}

	private void setRecordList() {
		fragment = new RecordListFragment();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace( R.id.record_container, fragment );
        transaction.commit();
	}

	private void initFindViews(){
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.action_settings:
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (detector.onTouchEvent(event)) {
			return true;
		}
		else {
			return super.onTouchEvent(event);
		}
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		float dx = Math.abs(velocityX);
		float dy = Math.abs(velocityY);
		if (dx > dy && dx > 200) {
			if (e1.getX() > e2.getX()) {
				Log.e("", "Fly Left");
				fragment.moveLeftDetail();
			}
			else {
				fragment.moveRightDetail();
			}
		}
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}
}
